package com.buli.blmall.admin.system.service;

import com.buli.blmall.admin.system.entity.SysRoleMenu;
import com.buli.blmall.admin.system.vo.SysRoleMenuVO;
import com.buli.blmall.admin.system.mapper.SysRoleMenuMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import cn.hutool.core.bean.BeanUtil;
import java.util.List;

/**
 * <p>
 * 角色菜单 服务类
 * </p>
 *
 * @author buli
 * @since 2025-02-27
 */
@Service
public class SysRoleMenuService extends ServiceImpl<SysRoleMenuMapper, SysRoleMenu> {

    /**
     * 查询角色菜单详情
     *
     * @param id
     * @return 角色菜单详情
     */
    public SysRoleMenuVO info(Long id) {
        return BeanUtil.copyProperties(getById(id), SysRoleMenuVO.class );
    }

    /**
     * 查询角色菜单集合
     *
     * @param sysRoleMenuVo
     * @return 角色菜单集合
     */
    public List<SysRoleMenuVO> queryList(SysRoleMenuVO sysRoleMenuVo) {
        LambdaQueryWrapper<SysRoleMenu> queryWrapper = new LambdaQueryWrapper<>();
        List<SysRoleMenu> list = list(queryWrapper);
        return BeanUtil.copyToList(list, SysRoleMenuVO.class );
    }

    /**
     * 新增角色菜单
     * @param sysRoleMenuVo
     * @return boolean
     */
    public boolean add(SysRoleMenuVO sysRoleMenuVo) {
        SysRoleMenu sysRoleMenu = BeanUtil.copyProperties(sysRoleMenuVo, SysRoleMenu.class );
        return save(sysRoleMenu);
    }

    /**
     * 编辑角色菜单
     * @param sysRoleMenuVo
     * @return boolean
     */
    public boolean edit(SysRoleMenuVO sysRoleMenuVo) {
        SysRoleMenu sysRoleMenu = BeanUtil.copyProperties(sysRoleMenuVo, SysRoleMenu.class );
        return updateById(sysRoleMenu);
    }

    /**
     * 删除角色菜单
     * @param id
     * @return boolean
     */
    public boolean delete(Long id) {
        return removeById(id);
    }

    /**
     * 根据角色查询菜单
     * @param roleIds
     * @return
     */
    public List<SysRoleMenu> getListByRoleIds(List<Long> roleIds) {
        LambdaQueryWrapper<SysRoleMenu> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(SysRoleMenu::getRoleId, roleIds);
        return list(queryWrapper);
    }
}
